﻿class com.generalv.utils.Dumper {
	static var maxLevel = 10;
	static var maxCount = 1000;
	static var enabled=true;
	public static function dump(obj, msg) {
		if(!enabled){
			return
		}
		msg = msg ? msg : 'var-dump';
		trace('--------' + msg + '----------');
		trace('+' + String(obj));
		_dumpLevel(obj, 1, 0);
		trace('');
	}
	static function _dumpLevel(data, level, count) {
		count++;
		if (count > maxCount) {
			return count;
		}
		if (level >= maxLevel) {
			trace(_space(level) + '[reach the max level ...]');
			return count;
		}
		for (var q in data) {
			if (data[q]) {
				trace(_space(level) + q + ':' + String(data[q]));
				count = _dumpLevel(data[q], level + 1, count);
				if (count > maxCount) {
					return count;
				}
			}
		}
		return count;
	}
	static function _space(t) {
		var a = new Array();
		a.push('');
		for (var i = 0; i < t - 1; i++) {
			a.push('  ');
		}
		a.push('--');
		return a.join('|');
	}
}
